//
//  GuideMeViewController.m
//  GuideMe
//
//  Created by Amila Fonseka on 3/24/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "GuideMeViewController.h"
#import "TourDetailsController.h"
#import "TourCell.h"

@implementation GuideMeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tabelView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 60.0;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	if(section==0)
    {
        return 3;
        //            if ([arrPlaces count] > 0)
        //                return [arrPlaces count];
        //            return 0;
    }
	
	return 0;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{	
	static NSString *EmptyCellIdentifier = @"EmptyCell";
	
	UITableViewCell *emptyCell = [tableView dequeueReusableCellWithIdentifier:EmptyCellIdentifier];
	if (emptyCell == nil)
	{
		emptyCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:EmptyCellIdentifier] autorelease];   
		emptyCell.detailTextLabel.textAlignment = UITextAlignmentLeft;
		emptyCell.selectionStyle = UITableViewCellSelectionStyleNone;
	}
    
    static NSString *TourCellIdentifier = @"TourCell";		
	
	TourCell *tCell = (TourCell *)[tableView dequeueReusableCellWithIdentifier:TourCellIdentifier];
	if (tCell == nil)
	{
		tCell = [[[TourCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TourCellIdentifier] autorelease];
		tCell.selectionStyle = UITableViewCellSelectionStyleNone;
	}
    
	if (indexPath.row == 0)
    {
        tCell.lblTourName.text = @"Tour De GALLE TO MATARA";
        tCell.lblTourType.text = @"Adventure";
        tCell.lblTourOffer.hidden = YES;
        return tCell;
    }
    else if (indexPath.row == 1)
    {
        tCell.lblTourName.text = @"Tour Mystory Island";
        tCell.lblTourType.text = @"Historical";
        tCell.lblTourOffer.hidden = YES;
        return tCell;
    }
    else if (indexPath.row == 2)
    {
        tCell.lblTourName.text = @"Rock trips - By Guiller Travels";
        tCell.lblTourType.text = @"Rock";
        tCell.lblTourOffer.hidden = NO;
        tCell.lblTourOffer.text = @"20% Off";
        return tCell;
    }
    else
    {
        emptyCell.detailTextLabel.frame = CGRectMake(20.0, 10.0, 280.0, 30.0);
        emptyCell.contentView.backgroundColor = [UIColor whiteColor];
        emptyCell.detailTextLabel.text = @"Sorry there are no tours at the moment";
        return emptyCell;
    }
    return emptyCell;	
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        TourDetailsController *tourView = [[TourDetailsController alloc] initWithNibName:@"TourDetailsController" bundle:nil];
        tourView.strTourID = [NSString stringWithFormat:@"%d", (indexPath.row+1)];
        tourView.strTourTitle = @"Tour De GALLE TO MATARA";
        tourView.strPurchasable = @"NO";
        [self.navigationController pushViewController:tourView animated:YES];
        [tblPlaces deselectRowAtIndexPath:indexPath animated:YES];
        [tourView release];
    }
    else if (indexPath.row == 1)
    {
        TourDetailsController *tourView = [[TourDetailsController alloc] initWithNibName:@"TourDetailsController" bundle:nil];
        tourView.strTourID = [NSString stringWithFormat:@"%d", (indexPath.row+1)];
        tourView.strTourTitle = @"Tour Mystory Island";
        tourView.strPurchasable = @"NO";
        
        [self.navigationController pushViewController:tourView animated:YES];
        [tblPlaces deselectRowAtIndexPath:indexPath animated:YES];
        [tourView release];
    }
    else if (indexPath.row == 2)
    {
        TourDetailsController *tourView = [[TourDetailsController alloc] initWithNibName:@"TourDetailsController" bundle:nil];
        tourView.strTourID = [NSString stringWithFormat:@"%d", (indexPath.row+1)];
        tourView.strTourTitle = @"Rock trips - By Guiller Travels";
        tourView.strPurchasable = @"YES";
        
        [self.navigationController pushViewController:tourView animated:YES];
        [tblPlaces deselectRowAtIndexPath:indexPath animated:YES];
        [tourView release];
    }
}


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
